<template>
	<view>
		<!-- 视频 -->
		<video id="myVideo" danmu-btn enable-play-gesture show-mute-btn :src="url"></video>
		<!-- 视频作者 -->
		<view class="card">
			<view class="creator">
				<image class="avatar" :src="comments.artists[0].img1v1Url">
				</image>
				<view class="nickName">
					{{comments.artists[0].name}}
				</view>
				<button class="btn" open-type="share" size="mini">
					<image src="../../static/images/share.png" class="share" mode="widthFix"></image>
				</button>
			</view>
			<view class="videoInfo">
				<view class="title">
					{{comments.name+' - '+ comments.artistName}}
				</view>
				<scroll-view scroll-y class="desp-scroll" v-if="comments.desc">
					<view class="desp">{{comments.desc?comments.desc:''}}</view>
				</scroll-view>
			</view>
		</view>
		<!-- 评论列表区域 -->
		<scroll-view class="comments-scroll" scroll-y>
			<!-- 头部 -->
			<view class="header">评论区 ({{comments.commentCount}})</view>
			<view class="commentList" v-for="(item,index) in userComments" :key="index">
				<image class="avatar" :src="item.user.avatarUrl" lazy-load></image>
				<view class="commentInfo">
					<view class="creatorInfo">
						<view class="nickName">{{item.user.nickname}}</view>
						<view class="createTime">{{item.timeStr}}</view>
					</view>
					<view class="commentContent">{{item.content}}</view>
				</view>
			</view>
		</scroll-view>
	</view>
</template>

<script>
	import {
		playMv,
		getMvComment,
		getUserComment
	} from '../../service/songs.js'
	export default {
		data() {
			return {
				videoId: 0,
				url: '',
				comments: [],
				userComments: []
			}
		},
		onLoad(option) {
			this.videoId = option.id
			// 获取mv的url
			this._videoPlay()
			// 获取mv的评论数据
			this._videoComment()
			// 获取用户评论区
			this._getUserComment()
		},
		// 按钮的开放能力
		onShareAppMessage: function({
			from
		}) {
			console.log(from);
			if (from === 'button') {
				return {
					title: this.comments.name,
					imageUrl: this.comments.cover
				}
			} else if (from === 'menu') {
				return {
					title: this.comments.name,
					imageUrl: this.comments.cover
				}
			}
		},
		methods: {
			// 根据id获取视频在线url
			_videoPlay() {
				playMv(this.videoId).then(res => {
					this.url = res.data.url
				})
			},
			// 获取mv的评论数据
			_videoComment() {
				getMvComment(this.videoId).then(res => {
					this.comments = res.data
					// console.log('mv评论总数据',this.comments)
				})
			},
			// 获取用户评论区
			_getUserComment() {
				getUserComment(this.videoId).then(res => {
					this.userComments = res.data.comments
				})
			}

		}
	}
</script>

<style lang="less">
	#myVideo {
		width: 100%;
	}

	.comments-scroll {
		.header {
			height: 65rpx;
			width: 100%;
			line-height: 50rpx;
			font-size: 30rpx;
			font-weight: 600;
			color: #3c3737;
			padding: 10rpx 40rpx 10rpx;
		}

		.commentList {
			display: flex;
			padding-top: 20rpx;
			margin: 0 30rpx;
			border-bottom: 1rpx solid #b0b0b0;

			.avatar {
				height: 85rpx;
				width: 85rpx;
				border-radius: 50%;
			}

			.commentInfo {
				flex: 1;
				display: flex;
				flex-direction: column;
				margin-left: 20rpx;
				padding-bottom: 15rpx;

				.creatorInfo {
					margin-top: 8rpx;

					.nickName {
						font-size: 30rpx;
						font-weight: 500;
					}

					.createTime {
						color: #aaa;
						font-size: 25rpx;
					}
				}

				.commentContent {
					font-size: 30rpx;
					margin: 15rpx 0;
					width: 95%;
				}
			}
		}

	}

	.card {
		margin: 20rpx;
		padding: 20rpx;
		background-color: white;
		border-radius: 20rpx;
		border: 1rpx solid #b0b0b0;
		box-sizing: border-box;

		.creator {
			position: relative;
			display: flex;
			align-items: center;

			.avatar {
				width: 90rpx;
				height: 90rpx;
				border-radius: 50%;
				margin: 0 25rpx 0 15rpx;
			}

			.nickName {
				font-size: 30rpx;
				font-weight: 600;
			}

			.btn {
				position: absolute;
				top: 10rpx;
				right: 10rpx;
				background-color: #fff;
				text-align: center;
				font-size: 30rpx;

				.share {
					display: inline-block;
					width: 40rpx;
					vertical-align: middle;
				}
			}
		}

		.videoInfo {
			margin: 20rpx 20rpx 0;

			.title {
				font-size: 30rpx;
			}

			.desp-scroll {
				height: 150rpx;

				.desp {
					margin-top: 15rpx;
					color: #bbb;
					font-size: 28rpx;
				}
			}
		}


	}
</style>